# 
# str_split_equal <- function(str)
# 
# library(stringr)
cell_fill <- function(str = "", max_leng = 0){
  if(max_leng == 0){
    return(paste("\\makecell[l]{", str, "}", sep = ""))
  }
}
# 
# 
# make_latex_table_split <- function(data = data.frame(), max_len = vec()){
#   if(length(max_len) != dim(data)[2]){
#     cat("\nERROR: length not same!\n")
#     return()
#   }
#   for(i in 1:dim(data)[1]){
#     cat("\\hline")
#     for(j in 1:length(max_len)){
#       cat(cell_fill(data[i,j], max_len[j]))
#       cat(" &")
#     }
#   }
# }

incert_in_vec <- function(vec = c(), incert = ""){
  out_str <- ""
  for(i in 1:(length(vec)-1)){
    out_str <- paste(out_str, vec[i], incert, sep = "")
  }
  i <- i + 1
  out_str <- paste(out_str, vec[i], sep = "")
  return(out_str)
}



make_latex_table <- function(data = data.frame()){
  outstring <- paste("\\begin{table*}[!h]\n\\centering\n\\begin{tabular}{",
                     incert_in_vec(vec = rep("|", dim(data)[2] + 1), incert = "c")
                     ,"}\n\\hline", sep = "")
  outstring <- paste(outstring, "\n", incert_in_vec(cell_fill(str = names(data)), " & "), 
                     "\\\\\n\\hline", sep = "")
  for(i in 1:dim(data)[1]){
    packup <- cell_fill(str = data[i,])
    outstring <- paste(outstring, "\n", incert_in_vec(packup, " & "), "\\\\\n\\hline", sep = "")
  }
  outstring <- paste(outstring, "\n\\end{tabular}\n\\end{table*}\n", sep = "")
  return(outstring)
}

#### TEST AREA ####

# incert_in_vec(vec = c("a", "b", "c"), incert = ", ")
# cell_fill("woaini")
# cell_fill(c("woaini", "woheini"))[2]
# cat(make_latex_table(data = data.frame(c(1,2,3),c("a","b","c"))))


